package algorithm;

import algorithm.sort.*;
import org.junit.Test;

import java.util.List;
import java.util.Random;

import static algorithm.TestUtils.*;
import static algorithm.TestUtils.testSpeed;

/**
 * @author xutao
 * created 2020/3/16 11:17
 */
public class MainTest {

    private Integer[] random = generatorRandomArray(100000, 0, 10000);
    private Integer[] orderedRandom = generatorOrderedRandomArray(1000000, 5, 0, 10000);


    //校验冒泡排序算法
    @Test
    public void bubbleTest() {
        testSpeed(BubbleSort.class, random);
        testSpeed(BubbleSort.class, orderedRandom);
    }


    //校验选择排序算法
    @Test
    public void selectionTest() {
        testSpeed(SelectionSort.class, random);
        testSpeed(SelectionSort.class, orderedRandom);
    }

    //校验插入排序算法
    @Test
    public void insertionTest() {
        testSpeed(InsertionSort.class, random);
        testSpeed(InsertionSort.class, orderedRandom);
    }

    //校验希尔排序算法
    @Test
    public void shellTest() {
        testSpeed(ShellSort.class, random);
        testSpeed(InsertionSort.class, random);
    }


    @Test
    public void mergeTest(){
        Integer[] array = generatorRandomArray(100000, 0, 20);
        testSpeed(MergeSort.class,array);
    }

    @Test
    public void mergeBuTest(){
        Integer[] array = generatorRandomArray(100000, 0, 20);
        testSpeed(MergeBUSort.class,array);
    }

    @Test
    public void quickTest(){
        Integer[] array =  generatorRandomArray(1000000, 0, 10000);

    }


    @Test
    public void maxHeapTest() throws Exception {
        Integer[] array = generatorRandomArray(10000, 0, 10000);
        testSpeed(MaxHeapSort.class,array);
    }

    @Test
    public void heapTest() throws Exception {
        Integer[] array = generatorRandomArray(10, 0, 1000);
        testSpeed(HeapSort.class,array);
    }


    //无序数组各个算法排序
    @Test
    public void randomTest() throws Exception {
        Integer[] array = generatorRandomArray(100000, 0, 10000);
        List<Class<? extends Sort>> list = getAlgorithms(Sort.class);
        testAlgorithmSpeed(list, array);
    }




    //整体有序的数组各个算法排序
    @Test
    public void orderRandom() throws Exception {
        Integer[] array = generatorOrderedRandomArray(100000, 7, 0, 10000);
        List<Class<? extends Sort>> list = getAlgorithms(Sort.class);
        testAlgorithmSpeed(list, array);
    }



    @Test
    public void tt(){
        Random random = new Random();
    }

}
